package uk.ac.sanger.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
import org.biojava.dasobert.dasregistry.DasSource;

public class DasCoordinateSystemGuesser {

Map<String,DasCoordinateSystem> uniqueIdToCoordMap;
private List<DasCoordinateSystem> knownCoords;

	public DasCoordinateSystemGuesser(List<DasCoordinateSystem> knownCoords2){
		this.knownCoords=knownCoords2;
		uniqueIdToCoordMap=new HashMap<String, DasCoordinateSystem>();
		
		for(DasCoordinateSystem coord:knownCoords2){
			//System.out.println("looking for:"+coord.getUniqueId());
			uniqueIdToCoordMap.put(coord.getUniqueId(),coord);
			
		}
	}
	
	public DasSource addGuesedCoordinate(DasSource source,
			DasCoordinateSystem[] coords) {
		
		DasCoordinateSystem[] newCoords=new DasCoordinateSystem[1];
		String csId="";
		if(coords.length==0 || coords==null){
			if(source.getId().contains("_m37") || source.getId().equals("mouse_fosmids")){
				//add a the mouse 37 cooord
				//System.out.println("_m37"+source.getId()+" "+source.getDescription());
				
				csId="CS_DS108";
			}
			if(source.getId().contains("_36") || source.getId().contains("NCBI36") || source.getId().contains("hs36") || source.getId().contains("toronto_poly") || source.getId().contains("spectral36")){
				//System.out.println("_36="+source.getId()+" "+source.getDescription());
				csId="CS_DS40";
				
			}
			if(source.getId().contains("_35") || source.getId().contains("NCBI35") || source.getId().contains("hs35")|| source.getId().contains("ens3335genes")){
				//System.out.println("_35="+source.getId()+" "+source.getDescription());
				csId="CS_DS5";
				
			}
			if(source.getId().contains("_m36")){
				//System.out.println("_m36="+source.getId()+" "+source.getDescription());
				csId="CS_DS65";
			}
			if(source.getId().contains("_m35")){
			csId="CS_DS44";	
			}
			if(source.getId().contains("_m34")){
				csId="CS_DS30";	
				}
			if(source.getId().contains("rgsc_31")){//rat
				csId="CS_DS502";	
				}
			if(source.getId().contains("rat34")){//rat
				csId="CS_DS31";	
				}
			
			if(source.getId().contains("_Zv4")){
				csId="CS_DS10";	
				}
			//CS_DS25
			if(source.getId().contains("_Zv5")){
				csId="CS_DS25";	
				}
			if(source.getId().contains("_m33")){
				csId="CS_DS504";	
				}
			if(source.getId().contains("_34_") || source.getId().contains("spectral34")){
				csId="CS_DS134";	
				}
			if(source.getId().equals("Cosmic_Protein_Mutation")){
				csId="CS_DS6";
			}
			if(source.getId().equals("iPfamDomain")){
				csId="CS_DS73";
			}
			
			if(csId!="")addCoordWithUniqueId(csId,source, newCoords);
		}
		return source;
	}

	private void addCoordWithUniqueId(String uniqueId,DasSource source,
			DasCoordinateSystem[] newCoords) {
		newCoords[0]=uniqueIdToCoordMap.get(uniqueId);
		source.setCoordinateSystem(newCoords);
	}
	
}
